/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package liarbry;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
/**
 *
 * @author Administrator
 */
public class NewJFrame4 extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame4
     */
    public NewJFrame4() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("账号：");

        jLabel2.setText("密码：");

        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jButton1.setText("登录");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("注册");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("忘记密码");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel3.setText("          ");

        jLabel4.setText("201621123012 林志伟");

        jLabel5.setText("201621123012 郑玉波");

        jLabel6.setText("201621123028 占恒");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(7, 7, 7)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addGap(42, 42, 42)
                                .addComponent(jButton2))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jTextField1)
                                    .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE))
                                .addGap(52, 52, 52)
                                .addComponent(jLabel3))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(148, 148, 148)
                        .addComponent(jButton3)))
                .addContainerGap(75, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(101, 101, 101))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(32, 32, 32))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(48, 48, 48)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(18, 18, 18)
                .addComponent(jButton3)
                .addContainerGap(59, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        this.dispose();
        new NewJFrame6().setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
         String s = jTextField2.getText();
         String s1 = jTextField1.getText();
        int  k = yonghu.search(s);
        
        if(k<0){
            jLabel3.setText("该账号不存在");
        }
        else if(yonghu.user.get(k).key.equals(s1)){
            no.fuzhi(yonghu.user.get(k).no);
            this.dispose();
           new NewJFrame().setVisible(true);
        }
        else{
              jLabel3.setText("密码错误");
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        this.dispose();
             new NewJFrame7().setVisible(true);
    }//GEN-LAST:event_jButton3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewJFrame4.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewJFrame4.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewJFrame4.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame4.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
               yonghu.start();
               tushu.start();
               xinxi.start();
                new NewJFrame4().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
}
 class yonghu {

	String ID;
	String key;
	int no;
         String youxiang;
	static  ArrayList<yonghu> user = new ArrayList<yonghu>(); 

	public static void start(){
		// TODO Auto-generated method stub
		List<String> a= new ArrayList<String>();
		try {
			FileInputStream in = new FileInputStream("E:/liarbry/yonghu.txt");
			InputStreamReader inReader = new InputStreamReader(in);
			BufferedReader bufReader = new BufferedReader(inReader);
			String line = null;
			
			int i = 1;
			while((line = bufReader.readLine()) != null){
			
			a.add(line);
			
				i++;
			}
			for (int i1 = 0; i1 < a.size(); i1++) {
				String[] b =a.get(i1).split(" ");
				new yonghu(b[0],b[1],b[2],Integer.parseInt(b[3]));
			}
			
			bufReader.close();
			inReader.close();
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("读取" + "E:/liarbry/yonghu.txt" + "出错！");
		}
		

	

	}
	public yonghu(String iD, String key,String youxiang,int no) {
		
		this.ID=iD;
		this.key = key;
		this.no = no;
                this.youxiang=youxiang;
		user.add(this);
	}

	

public static void close(){
	try {
		FileOutputStream out = new FileOutputStream("E:/liarbry/yonghu.txt");
		OutputStreamWriter outWriter = new OutputStreamWriter(out, "UTF-8");
		BufferedWriter bufWrite = new BufferedWriter(outWriter);
		for (int i = 0; i < user.size(); i++) {
		
			bufWrite.write(user.get(i).ID+" " +user.get(i).key+ " "+user.get(i).youxiang+" "+user.get(i).no);
			bufWrite.newLine();
		}
			
		
		bufWrite.close();
		outWriter.close();
		out.close();
	} catch (Exception e) {
		e.printStackTrace();
		System.out.println("读取" + "E:/liarbry/yonghu.txt" + "出错！");
	}		
}
public static int search(String Name) {
	for (int i = 0; i < user.size(); i++) {
		if(user.get(i).ID.equals(Name)){
		
			return i;
		}
		
	}
	return -1;
}
}
class tushu {
  String bookname;
  String author;
  int num;	
  static  ArrayList<tushu> tushu = new ArrayList<tushu>(); 
  static  List<Integer> l = new ArrayList<Integer>(); 
public tushu(String bookname, String author, int num) {
	super();
	this.bookname = bookname;
	this.author = author;
	this.num = num;
   tushu.add(this);

}
public static void start(){
	// TODO Auto-generated method stub
	List<String> a= new ArrayList<String>();
	try {
		FileInputStream in = new FileInputStream("E:/liarbry/tushu.txt");
		InputStreamReader inReader = new InputStreamReader(in );
		BufferedReader bufReader = new BufferedReader(inReader);
		String line = null;
		
		int i = 1;
		while((line = bufReader.readLine()) != null){
		
		a.add(line);
		
			i++;
		}
		for (int i1 = 0; i1 < a.size(); i1++) {
			String[] b =a.get(i1).split(" +");
		
			int c= Integer.parseInt(b[2]);
			new tushu(b[0],b[1],c);
		}
		
		bufReader.close();
		inReader.close();
		in.close();
	} catch (Exception e) {
		e.printStackTrace();
		System.out.println("读取" + "E:/liarbry/tushu.txt" + "出错！");
	}
	



}
public static void close(){
	try {
		FileOutputStream out = new FileOutputStream("E:/liarbry/tushu.txt");
		OutputStreamWriter outWriter = new OutputStreamWriter(out );
		BufferedWriter bufWrite = new BufferedWriter(outWriter);
		for (int i = 0; i < tushu.size(); i++) {
		
			bufWrite.write(tushu.get(i).bookname+" " +tushu.get(i).author+ " "+tushu.get(i).num);
			bufWrite.newLine();
		}
			
		
		bufWrite.close();
		outWriter.close();
		out.close();
	} catch (Exception e) {
		e.printStackTrace();
		System.out.println("读取" + "E:/liarbry/yonghu.txt" + "出错！");
	}		
}
public static List<Integer> searchbookname(String Name) {
	List<Integer> h= new ArrayList<Integer>();
	for (int i = 0; i < tushu.size(); i++) {
		
		if(tushu.get(i).bookname.contains(Name)){
		h.add(i);
		}
		
	}
	return h;
	
}
public static List<Integer> searchbookauthor(String Name) {
	List<Integer> h= new ArrayList<Integer>();
	for (int i = 0; i < tushu.size(); i++) {
		if(tushu.get(i).author.contains(Name)){
		h.add(i);
		}
		
	}
	return h;
}
public static int search(String Name) {
	for (int i = 0; i < tushu.size(); i++) {
		if(tushu.get(i).bookname.equals(Name)){
		
			return i;
		}
		
	}
	return -1;
}
}

 class xinxi {
 String name;
 String author;
 String data;
 int no;
 static  ArrayList<xinxi> xinxi = new ArrayList<xinxi>(); 
 public static void start(){
		// TODO Auto-generated method stub
		List<String> a= new ArrayList<String>();
		try {
			FileInputStream in = new FileInputStream("E:/liarbry/xinxi.txt");
			InputStreamReader inReader = new InputStreamReader(in );
			BufferedReader bufReader = new BufferedReader(inReader);
			String line = null;
			
			int i = 1;
			while((line = bufReader.readLine()) != null){
			
			a.add(line);
			
				i++;
			}
                        if(!a.isEmpty())
			for (int i1 = 0; i1 < a.size(); i1++) {
				String[] b =a.get(i1).split(" ");
                                new xinxi(b[0],b[1],b[2],Integer.parseInt(b[3]));
			}
			
			bufReader.close();
			inReader.close();
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("读取" + "E:/liarbry/xinxi.txt" + "出错！");
		}
		



	}
public xinxi(String name,String author,String data, int no) {
	super();
	this.name = name;
        this.author=author;
	this.data = data;
	this.no = no;
	xinxi.add(this);
}
public static void close(){
	try {
		FileOutputStream out = new FileOutputStream("E:/liarbry/xinxi.txt");
		OutputStreamWriter outWriter = new OutputStreamWriter(out );
		BufferedWriter bufWrite = new BufferedWriter(outWriter);
		for (int i = 0; i < xinxi.size(); i++) {
		
			bufWrite.write(xinxi.get(i).name+" " +xinxi.get(i).author+" "+xinxi.get(i).data+ " "+xinxi.get(i).no);
			bufWrite.newLine();
		}
			
		
		bufWrite.close();
		outWriter.close();
		out.close();
	} catch (Exception e) {
		e.printStackTrace();
		System.out.println("读取" + "E:/liarbry/yonghu.txt" + "出错！");
	}		
}
public static int search(String Name) {
	for (int i = 0; i < xinxi.size(); i++) {
		if(xinxi.get(i).name.equals(Name)){
		
			return i;
		}
		
	}
	return -1;
}
 
}
class no{
    static public int x=0;
    public static void fuzhi(int zhi){
        x=zhi;
    }
}